package com.sky.config;

import com.sky.utils.MinioUtil;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "sky.minio")
public class MinioConfig {
    private String endpoint;
    private String accessKeyId; // 对应配置文件的 access-key-id
    private String accessKeySecret; // 对应配置文件的 access-key-secret
    private String bucketName;

    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKeyId, accessKeySecret) // 使用正确的 accessKeyId 和 secret
                .build();
    }

    @Bean
    public MinioUtil minioUtil() { // 直接使用配置类属性构造 MinioUtil
        return new MinioUtil(
                endpoint,
                accessKeyId,
                accessKeySecret,
                bucketName
        );
    }
}